<template>
	<view class="container">
		<view class="main">
			<view class="goods_bg">
				<view class="goods_bg_left">
					<text class="red">*</text><text class="text">手机号码</text>
				</view>
				<view class="goods_bg_right" @click="gotoGoods()">
					<input v-model="mobile" value="17823117840"/>
				</view>
			</view><!--goods_bg end-->
			
			<view class="bottom_bg">
				<view class="num_bg">
					<view class="title_bg"><text class="star">*</text><text class="name">乘车人数</text></view>
					<view class="section">
						<view class="minus" @click="minusEvent()">-</view>
						<input  class="num" type="number" value="1" v-model="num"/>
						<view class="add" @click="addEvent()">+</view>
					</view>
				</view>
			</view><!--bottom_bg end-->
			<view class="remark_bg">
				<view class="up">
					<text class="red">*</text><text class="text">备注</text>
				</view>
				<view class="down">
					<view class="down_bg">
						<textarea v-model="remark" class="textarea" placeholder="请输入上车地点或备注信息"></textarea>
					</view>
				</view>
			</view><!--goods_bg end-->
			<view class="protocol_bg">
				<image class="radio" v-if="!check" @click="selectProtocol()" src="../../../static/images/radio_normal.png"></image>
				<image class="radio" v-else @click="selectProtocol()" src="../../../static/images/radio_selected.png"></image>
				<view class="text">我已阅读并同意出行拼车</view>
				<view class="role">《出行协议》</view>
			</view><!--protocol_bg end-->
		</view><!--main end-->
		<view class="footer">
			<view class="submit-btn" @click="submitEvent()">确认预订</view>
		</view>
		
	</view>
</template>

<script>
	import {subscribe} from '@/api/travel.js';
	export default {
		data() {
			return {
				id:0,
				num:1,
				has_location:1,
				mobile:'17823117840',
				remark:'',
				check:false
			}
		},
		onLoad(options) {
			this.has_location = options.has_location;
			this.id = options.id;
		},
		methods: {
			minusEvent(){
				if(this.num > 1){
					this.num = this.num - 1;
				}
			},
			addEvent(){
				if((this.num + 1)<= this.has_location){
					this.num = this.num + 1;
				}else{
					uni.showToast({
						icon:'none',
						title:'不能超过余座'
					})
				}
			},
			selectProtocol(){
				this.check = !this.check;
			},
			submitEvent(){
				
				if(this.has_location == 0){
					uni.showToast({
						icon:'none',
						title:'预订失败，没有余座'
					})
					return;
				}
				if(this.mobile == 0){
					uni.showToast({
						icon:'none',
						title:'请填写手机号码'
					})
					return;
				}
				if(this.remark == 0){
					uni.showToast({
						icon:'none',
						title:'请填写备注'
					})
					return;
				}
				if(!this.check){
					uni.showToast({
						icon:'none',
						title:'请查看并同意协议'
					})
					return;
				}
				let params = {
					pid:this.id,
					num:this.num,
					mobile:this.mobile,
					remark:this.remark
				};
				uni.showLoading({
					title:'预订中...'
				});
				subscribe(params).then(res => {
					uni.hideLoading();
					if(res){
						uni.showToast({
							icon:'none',
							title:'预订成功'
						});
						setTimeout(function(){
							uni.navigateBack();
						},1000);
					}
					
				}).catch(err => {
					uni.hideLoading();
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #f2f2f2;
	}
	.container{
		display: flex;
		flex-direction: column;
		.main{
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			padding-bottom: 0;  
			padding-bottom: constant(safe-area-inset-bottom);  
			padding-bottom: env(safe-area-inset-bottom); 
			margin-bottom: 100;
			.add_main{
				display: flex;
				flex-direction: column;
				background-color: white;
				.temp_bg{
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;
					background-color: blanchedalmond;
					height: 70rpx;
					.left{
						display: flex;
						flex-direction: row;
						align-items: center;
						.temp_icon{
							width: 30rpx;
							height: 30rpx;
							margin-left: 30rpx;
						}
						.temp_text{
							color: black;
							font-size: 28rpx;
							margin-left: 10rpx;
						}
					}
					.right{
						color: darkorange;
						font-size: 28rpx;
						margin-right: 20rpx;
					}
				}//temp_bg end
				.add-bg{
					display: flex;
					flex-direction: column;
					.section{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						align-items: center;
						height: 130rpx;
						.sec_left{
							display: flex;
							flex-direction: row;
							align-items: center;
							margin-left: 30rpx;
							margin-right: 30rpx;
							flex:1;
							.sec_l_icon{
								width: 40rpx;
								height: 40rpx;
								text-align: center;
								line-height: 40rpx;
								background-color: #008CFF;
								color: white;
								border-radius: 6rpx;
								font-size: 20rpx;
							}
							.sec_l_icon_org{
								width: 40rpx;
								height: 40rpx;
								text-align: center;
								line-height: 40rpx;
								background-color: orange;
								color: white;
								border-radius: 6rpx;
								font-size: 20rpx;
							}
							.sec_l_text{
								color: gray;
								font-size: 30rpx;
								font-weight: bold;
								margin-left: 30rpx;
							}
						}
						.sec_right{
							width: 100rpx;
							display: flex;
							flex-direction: column;
							align-items: center;
							.sec_r_icon{
								width: 30rpx;
								height: 30rpx;
							}
							.sec_r_text{
								color: gray;
								font-size: 28rpx;
							}
						}
					}//section end
					.line_bottom{
						border-bottom: 1rpx solid #f1f1f1;
					}
				}//add-bg end
				.add_desc{
					background-color: #f8f8f8;
					color: gray;
					font-size: 28rpx;
					height: 80rpx;
					line-height: 80rpx;
					padding: 0 30rpx;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					.distance{
						color: orange;
					}
				}
			}//add_main end
			.goods_bg{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				height: 100rpx;
				align-items: center;
				background-color: white;
				padding: 0rpx 30rpx;
				.goods_bg_left{
					display: flex;
					flex-direction: row;
					align-items: center;
					width: 200rpx;
					.red{
						color: red;
					}
					.text{
						color: black;
						font-size: 28rpx;
					}
				}
				.goods_bg_right{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-left: 30rpx;
					flex-wrap: nowrap;
					.goods_text{
						font-size: 28rpx;
						color: gray;
					}
					.goods_arrow{
						width: 26rpx;
						height: 26rpx;
					}
				}
			}//goods_bg end
			.bottom_bg{
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				background-color: white;
				padding: 30rpx 30rpx 30rpx 30rpx;
				.num_bg{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					.title_bg{
						display: flex;
						flex-direction: row;
						.star{
							font-size: 28rpx;
							color: red;
						}
						.name{
							font-size: 28rpx;
							color: black;
						}
					}
					.section{
						display: flex;
						flex-direction: row;
						align-items: center;
						.minus{
							width: 70rpx;
							height: 70rpx;
							line-height: 70rpx;
							text-align: center;
							background-color: #f2f2f2;
							text-align: center;
						}
						.num{
							width: 80rpx;
							font-size: 28rpx;
							background-color: #f2f2f2;
							text-align: center;
							height:70rpx;
							margin-left: 5rpx;
							margin-right: 5rpx;
							padding: 0rpx 20rpx;
						}
						.add{
							width: 70rpx;
							height: 70rpx;
							line-height: 70rpx;
							text-align: center;
							background-color: #f2f2f2;
							text-align: center;
						}
					}
				}
			}
			.remark_bg{
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				background-color: white;
				padding: 30rpx;
				.up{
					display: flex;
					flex-direction: row;
					.red{
						color: red;
					}
					.text{
						color: black;
						font-size: 28rpx;
					}
				}
				.down{
					margin-top: 30rpx;
					.down_bg{
						border: 1rpx solid #f1f1f1;
						padding: 10rpx;
						.textarea{
							height: 80rpx;
							width: 100%;
							padding: 10rpx;
						}
					}
				}
			}//remark_bg end
			.protocol_bg{
				display: flex;
				flex-direction: row;
				margin-bottom: 200rpx;
				margin-top: 30rpx;
				align-items: center;
				.radio{
					width: 40rpx;
					height:40rpx;
				}
				.text{
					margin-left: 10rpx;
					color: #000000;
					font-size: 28rpx;
				}
				.role{
					color: red;
					font-size: 28rpx;
				}
			}//protocol_bg
		}//main end
		
		.footer{
			height: 80rpx;
			width: 100%;
			position: fixed;
			right: 0;
			bottom: 0;
			left: 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			padding-bottom: 0;  
			padding-bottom: constant(safe-area-inset-bottom);  
			padding-bottom: env(safe-area-inset-bottom); 
			.submit-btn{
				background-color: $uni-main-color;
				color: white;
				font-size: 28rpx;
				height: 80rpx;
				width: 100%;
				text-align: center;
				line-height: 80rpx;
			}
		}// end footer
		/** 弹窗 **/
		.popup-cls{
			display: flex;
			flex-direction: column;
			.pop-info{
				width:100%;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				margin: 0 auto;
				background-color: white;
				.pop-top{
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					align-items: center;
					font-size: 28rpx;
					color: #000000;
					font-weight: bold;
					margin-top: 20rpx;
					text-align: center;
					height: 40rpx;
				}
			}
			
			.center{
				margin-top: 30rpx;
				width:100%;
				padding: 0rpx 0rpx;
				display: flex;
				flex-direction: column;
				.warning{
					color: darkorange;
					font-size: 28rpx;
					padding: 0 30rpx;
				}
				.pop-content{
					display: flex;
					flex-direction: column;
					height: 700rpx;
					margin-top: 30rpx;
					.list{
						display: flex;
						flex-direction: column;
						.top{
							display: flex;
							flex-direction: row;
							padding: 0 30rpx;
							.red{
								color: red;
							}
							.title{
								font-size: 28rpx;
								font-weight: bold;
								color: black;
							}
							.desc{
								font-size: 28rpx;
								color: gray;
							}
						}
						.bottom{
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							margin-top: 20rpx;
							// padding-left: 10rpx;
							.item{
								color: black;
								height:70rpx;
								line-height: 70rpx;
								margin-left: 30rpx;
								font-weight: bold;
							}
							.item-body{
								display: flex;
								flex-direction: row;
								flex-wrap: wrap;
								margin-top: 20rpx;
								.item-i{
									width: 16%;
									background-color: #f2f2f2;
									color: black;
									text-align: center;
									height:60rpx;
									line-height: 60rpx;
									margin-bottom: 20rpx;
									border-radius: 10rpx;
									border: 1rpx solid #f2f2f2;
									margin-left: 20rpx;
								}
								.item_selected{
									border: 1rpx solid orange;
									background-color: blanchedalmond;
									color: orange;
								}
							}
							//不能选择
							.item_unselected{
								border: 1rpx solid #f2f2f2;
								background-color: #f2f2f2;
								color: gray;
							}
						}
					}
				}
				//pop-content
				.btn{
					background-color: $uni-main-color;
					color: white;
					font-size: 28rpx;
					height: 80rpx;
					width: 100%;
					text-align: center;
					line-height: 80rpx;
				}
			}//center
			
		}//popup-cls end
	}
	
</style>
